package logic

import (
	"context"
	"person/userrpc/userrpc"

	"person/api/internal/svc"
	"person/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DetailLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
	return &DetailLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DetailLogic) Detail(req *types.DetailRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	detail, err := l.svcCtx.UserRpc.UserDetail(l.ctx, &userrpc.UserDetailRequest{UserId: req.UserId})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "查询成功",
		Data:    detail,
		Code:    200,
	}, nil

}
